<template>
    <div>
        <Modal v-model="modal.add" title="添加" :mask-closable="false" @on-visible-change="changeModalVisibleResetForm('addForm', $event)" width="1020">
            <Form ref="addForm" :model="form" :label-width="120" :rules="validateRules">
                <Row>
	<i-col span="12">
	<FormItem label="模板编号" prop="templateId">
	<InputNumber v-model="form.templateId" placeholder="请输入模板编号" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="物流公司" prop="expressCompany">
	<Input v-model="form.expressCompany" placeholder="请输入物流公司" clearable/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="省收货地" prop="province">
	<Input v-model="form.province" placeholder="请输入省收货地" clearable/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="市收货地" prop="city">
	<Input v-model="form.city" placeholder="请输入市收货地" clearable/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="区县收货地" prop="district">
	<Input v-model="form.district" placeholder="请输入区县收货地" clearable/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="是否包邮" prop="expressFree">
	    
	        <Select v-model="form.expressFree" placeholder="是否包邮" filterable clearable>
	          <Option
	            v-for="(option, index) in expressFreeSelect"
	            :value="option.value"
	            :key="index"
	          >{{option.displayValue}}</Option>
	        </Select>
	    
	</FormItem>

	</i-col>

	<i-col span="12">
	<FormItem label="快递费" prop="expressFee">
	<InputNumber v-model="form.expressFee" placeholder="请输入快递费" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="规格" prop="expressSpec">
	<InputNumber v-model="form.expressSpec" placeholder="请输入规格" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="递增规格" prop="incrementSpec">
	<InputNumber v-model="form.incrementSpec" placeholder="请输入递增规格" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="递增快递费" prop="incrementFee">
	<InputNumber v-model="form.incrementFee" placeholder="请输入递增快递费" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="包邮条件" prop="freeCondition">
	<InputNumber v-model="form.freeCondition" placeholder="请输入包邮条件" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="包邮金额" prop="freeMaxPayment">
	<InputNumber v-model="form.freeMaxPayment" placeholder="请输入包邮金额" style="width: 100%;"/>
</FormItem>
	</i-col>
</Row>

            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="resetFormCancelModal('addForm', 'add')">取消</Button>
                <Button type="primary" size="large" @click="add" :loading="loading.add">添加</Button>
            </div>
        </Modal>
        <Modal v-model="modal.edit" title="修改" :mask-closable="false" @on-visible-change="changeModalVisibleResetForm('editForm', $event)" width="1020">
            <Form ref="editForm" :model="form" :label-width="120" :rules="validateRules">
                <Row>
	<i-col span="12">
	<FormItem label="模板编号" prop="templateId">
	<InputNumber v-model="form.templateId" placeholder="请输入模板编号" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="物流公司" prop="expressCompany">
	<Input v-model="form.expressCompany" placeholder="请输入物流公司" clearable/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="省收货地" prop="province">
	<Input v-model="form.province" placeholder="请输入省收货地" clearable/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="市收货地" prop="city">
	<Input v-model="form.city" placeholder="请输入市收货地" clearable/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="区县收货地" prop="district">
	<Input v-model="form.district" placeholder="请输入区县收货地" clearable/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="是否包邮" prop="expressFree">
	    
	        <Select v-model="form.expressFree" placeholder="是否包邮" filterable clearable>
	          <Option
	            v-for="(option, index) in expressFreeSelect"
	            :value="option.value"
	            :key="index"
	          >{{option.displayValue}}</Option>
	        </Select>
	    
	</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="快递费" prop="expressFee">
	<InputNumber v-model="form.expressFee" placeholder="请输入快递费" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="规格" prop="expressSpec">
	<InputNumber v-model="form.expressSpec" placeholder="请输入规格" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="递增规格" prop="incrementSpec">
	<InputNumber v-model="form.incrementSpec" placeholder="请输入递增规格" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="递增快递费" prop="incrementFee">
	<InputNumber v-model="form.incrementFee" placeholder="请输入递增快递费" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="包邮条件" prop="freeCondition">
	<InputNumber v-model="form.freeCondition" placeholder="请输入包邮条件" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="包邮金额" prop="freeMaxPayment">
	<InputNumber v-model="form.freeMaxPayment" placeholder="请输入包邮金额" style="width: 100%;"/>
</FormItem>
	</i-col>
</Row>

            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="resetFormCancelModal('editForm', 'edit')">取消</Button>
                <Button type="primary" size="large" @click="edit" :loading="loading.edit">修改</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
	import * as utils from '@/api/utils-v2'
	import * as ResponseStatus from '@/api/response-status'
    export default {
        name: 'ExpressTemplateItemAddEdit',
        data() {
            return {
                modal: {
                    add: false,
                    edit: false
                },
                loading: {
                    add: false,
                    edit: false
                },
				dataDictCodes: ['EXPRESS_FREE'],
				dataDictItems: {},
				expressFreeSelect:[],
				
                urls: {
                    addUrl: '/express-template-item/admin/save',
                    batchAddUrl: '/express-template-item/admin/batch-save',
                    editUrl: '/express-template-item/admin/update',
                    batchEditUrl: '/express-template-item/admin/batch-update'
                },
                form: {
                    templateId: null,
expressCompany: null,
province: null,
city: null,
district: null,
expressFree: null,
expressFee: null,
expressSpec: null,
incrementSpec: null,
incrementFee: null,
freeCondition: null,
freeMaxPayment: null,

                },
                validateRules: {
                    templateId: [
{type: 'integer', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
expressCompany: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 255, message: '必须1-255个字符', trigger: 'blur'}
],
province: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 50, message: '必须1-50个字符', trigger: 'blur'}
],
city: [
{type: 'string', min: 1, max: 50, message: '必须1-50个字符', trigger: 'blur'}
],
district: [
{type: 'string', min: 1, max: 50, message: '必须1-50个字符', trigger: 'blur'}
],
expressFree: [
{type: 'integer', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
expressFee: [
{type: 'number', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
expressSpec: [
{type: 'number', required: true, message: '此项为必须项', trigger: 'blur, change'}
],

                }
            }
        },
        computed: {},
        mounted() {
			utils.getDataDict(this.dataDictCodes).then(response => {
			  if (response) {
			    this.dataDictItems = response
			    utils.getSelectDictItems(this, 'EXPRESS_FREE', 'expressFree', 'expressFreeSelect')
			  }
			}).catch(error => {
			  console.log(error)
			})
		},
        methods: {
            changeModalVisibleResetForm(formRef, visible) {
                if (!visible) {
					this.$refs[formRef].resetFields()
					this.form.id = null
                }
            },
            resetFormCancelModal(formRef, modal) {
                this.modal[modal] = false
			    this.$refs[formRef].resetFields()
				this.form.id = null
            },
            add() {
                this.$emit('add')
            },
            edit() {
                this.$emit('edit')
            }
        }
    }
</script>

<style>
</style>
